<?php
add_theme_support( 'post-thumbnails' );
// theme thumbnail image
add_action( 'after_setup_theme', 'tdx_theme_setup' );
/**
 * Register our sidebars and widgetized areas.
 *
 */
function tdx_widgets_init() {

    register_sidebar( array(
        'name'          => 'Nội dung chân trang trái',
        'id'            => 'footer_1',
        'before_widget' => '<div class="col-md-6 first-col">',
        'after_widget'  => '</div>',
    ) );
    register_sidebar( array(
        'name'          => 'Nội dung chân trang giữa',
        'id'            => 'footer_2',
        'before_widget' => '<div class="col-md-3 hot_project">',
        'after_widget'  => '</div>',
    ) );
    register_sidebar( array(
        'name'          => 'Nội dung chân trang phải',
        'id'            => 'footer_3',
        'before_widget' => '<div class="col-md-3 social_connect">',
        'after_widget'  => '</div>',
    ) );
    // header
    register_sidebar( array(
        'name'          => 'Top hotline',
        'id'            => 'top_hotline',
        'before_widget' => '',
        'after_widget'  => '',
    ) );
    // partners
    register_sidebar( array(
        'name'          => 'Đối tác',
        'id'            => 'partners',
        'before_widget' => '',
        'after_widget'  => '',
    ) );

}
add_action( 'widgets_init', 'tdx_widgets_init', 2);

function tdx_theme_setup() {
  add_image_size( 'service-thumb', 345, 128, true ); // (cropped)
  add_image_size( 'product-thumb', 142, 136 );
  add_image_size( 'service-right-thumb', 180, 191);
  add_image_size( 'archive-thumb', 263, 215, true);
}
/**
 * trims text to a space then adds ellipses if desired
 * @param string $input text to trim
 * @param int $length in characters to trim to
 * @param bool $ellipses if ellipses (...) are to be added
 * @param bool $strip_html if html tags are to be stripped
 * @return string 
 */
function trim_text($input, $length, $ellipses = true, $strip_html = true) {
    //strip tags, if desired
    if ($strip_html) {
        $input = strip_tags($input);
    }
  
    //no need to trim, already shorter than trim length
    if (strlen($input) <= $length) {
        return $input;
    }
  
    //find last space within length
    $last_space = strrpos(substr($input, 0, $length), ' ');
    $trimmed_text = substr($input, 0, $last_space);
  
    //add ellipses (...)
    if ($ellipses) {
        $trimmed_text .= '...';
    }
  
    return $trimmed_text;
}